package com.ymatou.iapi.userservice.testcase;

import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.userservice.parameter.MarkBean;
import com.ymatou.iapi.userservice.parameter.enums.AppSourceEnum;
import com.ymatou.iapi.userservice.parameter.req.CreateUserReq;
import com.ymatou.iapi.userservice.parameter.resp.SingleuserbriefResp;
import com.ymatou.iapi.userservice.parameter.resp.UserDetailsInfoVoResp;
import com.ymatou.iapi.userservice.service.MarkCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.database.model.Userinfo;
import com.ymttest.database.model.Userinfoex;
import com.ymttest.database.sqlwapper.JUserWapper;
/**
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_Mark{
	private static MarkBean MarkBean;
	private static MarkCall MarkCall;
	private static JUserWapper jUserWapper;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("根据userid查询用户标签");
	}

	@Before
	public void caseUp() {
		MarkBean=new MarkBean();
		MarkCall=new MarkCall();
		jUserWapper=new JUserWapper();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(MarkCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_Mark_001() {
		Logger.start(true,"输入正常用户id,查询用户标签,成功");
		try {
			//数据由bi导入数据库 故提前预埋静态数据
			int uid=1;
			List<Map> lm=jUserWapper.selectUsermark(uid);
			Logger.debug(lm);
			MarkBean.setUserId(uid);
			MarkCall.setData(MarkBean);
			MarkCall.callService();
			Logger.verifyEquals("true", MarkCall.getString("Success"), "验证是否成功");
			Logger.verifyEquals("200", MarkCall.getString("ResponseCode"), "验证返回code是否正确");
			for (Map map : lm) {
				Logger.verifyIsContains(map.get("Mark").toString(), MarkCall.getJsonObject().getAsJsonArray("Result").toString(), "验证存在Result");
			}
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_Mark_002() {
		Logger.start(false,"输入不存在的用户id,查出空结果集");
		try {
			MarkBean.setUserId(999999999);
			MarkCall.setData(MarkBean);
			MarkCall.callService();	
			Logger.verifyEquals("true", MarkCall.getString("Success"), "验证是否成功");
			Logger.verifyEquals("200", MarkCall.getString("ResponseCode"), "验证返回code是否正确");
			Logger.verifyEquals(0, MarkCall.getJsonObject().getAsJsonArray("Result").size(), "验证存在Result");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_Mark_003() {
		Logger.start(false,"不输入用户id,失败");
		try {
			MarkBean.setUserId(null);
			MarkCall.setData(MarkBean);
			MarkCall.callService();	
			Logger.verifyEquals("false", MarkCall.getString("Success"), "验证是否成功");
			Logger.verifyEquals("100", MarkCall.getString("ResponseCode"), "验证返回code是否正确");
			Logger.verifyIsContains("无效的用户编号", MarkCall.getString("LastErrorMessage"), "验证返回LastErrorMessage");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}